package castlewarserver;

public class GameProxy implements castlewarserver.Game {
  private String _endpoint = null;
  private castlewarserver.Game game = null;
  
  public GameProxy() {
    _initGameProxy();
  }
  
  public GameProxy(String endpoint) {
    _endpoint = endpoint;
    _initGameProxy();
  }
  
  private void _initGameProxy() {
    try {
      game = (new castlewarserver.GameServiceLocator()).getGame();
      if (game != null) {
        if (_endpoint != null)
          ((javax.xml.rpc.Stub)game)._setProperty("javax.xml.rpc.service.endpoint.address", _endpoint);
        else
          _endpoint = (String)((javax.xml.rpc.Stub)game)._getProperty("javax.xml.rpc.service.endpoint.address");
      }
      
    }
    catch (javax.xml.rpc.ServiceException serviceException) {}
  }
  
  public String getEndpoint() {
    return _endpoint;
  }
  
  public void setEndpoint(String endpoint) {
    _endpoint = endpoint;
    if (game != null)
      ((javax.xml.rpc.Stub)game)._setProperty("javax.xml.rpc.service.endpoint.address", _endpoint);
    
  }
  
  public castlewarserver.Game getGame() {
    if (game == null)
      _initGameProxy();
    return game;
  }
  
  public java.lang.String info() throws java.rmi.RemoteException{
    if (game == null)
      _initGameProxy();
    return game.info();
  }
  
  public java.lang.String newGame(java.lang.String player) throws java.rmi.RemoteException{
    if (game == null)
      _initGameProxy();
    return game.newGame(player);
  }
  
  public void resetGame() throws java.rmi.RemoteException{
    if (game == null)
      _initGameProxy();
    game.resetGame();
  }
  
  public gameObjects.Unit getUnitAt(int index) throws java.rmi.RemoteException{
    if (game == null)
      _initGameProxy();
    return game.getUnitAt(index);
  }
  
  public gameObjects.Unit[] getAllUnits() throws java.rmi.RemoteException{
    if (game == null)
      _initGameProxy();
    return game.getAllUnits();
  }
  
  public gameObjects.Unit moveUnit(gameObjects.Unit unit, int x, int y) throws java.rmi.RemoteException{
    if (game == null)
      _initGameProxy();
    return game.moveUnit(unit, x, y);
  }
  
  public gameObjects.Unit[] attackUnit(gameObjects.Unit attacker, gameObjects.Unit defender) throws java.rmi.RemoteException{
    if (game == null)
      _initGameProxy();
    return game.attackUnit(attacker, defender);
  }
  
  public gameObjects.Unit attackCastle(gameObjects.Unit unit) throws java.rmi.RemoteException{
    if (game == null)
      _initGameProxy();
    return game.attackCastle(unit);
  }
  
  public gameObjects.Unit buyUnit(java.lang.String unitType, java.lang.String player) throws java.rmi.RemoteException{
    if (game == null)
      _initGameProxy();
    return game.buyUnit(unitType, player);
  }
  
  public boolean isEndOfGame() throws java.rmi.RemoteException{
    if (game == null)
      _initGameProxy();
    return game.isEndOfGame();
  }
  
  public void endTurn(java.lang.String player) throws java.rmi.RemoteException{
    if (game == null)
      _initGameProxy();
    game.endTurn(player);
  }
  
  public upgrades.Upgrade[] getUpgrades(java.lang.String player) throws java.rmi.RemoteException{
    if (game == null)
      _initGameProxy();
    return game.getUpgrades(player);
  }
  
  public boolean buyUpgrade(java.lang.String player, int index) throws java.rmi.RemoteException{
    if (game == null)
      _initGameProxy();
    return game.buyUpgrade(player, index);
  }
  
  public boolean isPlayerTaken(java.lang.String player) throws java.rmi.RemoteException{
    if (game == null)
      _initGameProxy();
    return game.isPlayerTaken(player);
  }
  
  public gameObjects.Castle getCastleOrange() throws java.rmi.RemoteException{
    if (game == null)
      _initGameProxy();
    return game.getCastleOrange();
  }
  
  public gameObjects.Castle getCastleBlue() throws java.rmi.RemoteException{
    if (game == null)
      _initGameProxy();
    return game.getCastleBlue();
  }
  
  public java.lang.String getActualPlayer() throws java.rmi.RemoteException{
    if (game == null)
      _initGameProxy();
    return game.getActualPlayer();
  }
  
  
}